package com.yjc.rabbitMQ.one;

import com.rabbitmq.client.*;
import com.sun.org.apache.bcel.internal.generic.NEW;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @author shkstart
 * @create 2022-07-30 9:59
 */
public class Product {

    private static final String QUUEUE_NAME = "mirrior_Hello_queue_product *(￣▽￣)";
    private static final String EXCHANGE_NAME = "fed_exchange";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.100.138");
        factory.setUsername("admin");
        factory.setPassword("123");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-max-priority", 10);
        channel.queueDeclare(QUUEUE_NAME, false, false, false, arguments);
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        channel.queueBind(QUUEUE_NAME, EXCHANGE_NAME, "routekey");

        for (int i = 1; i <= 10; i++) {
            String message = "hello world" + i;
            if (i == 5) {
                AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().priority(5).build();
                channel.basicPublish("", QUUEUE_NAME, properties, message.getBytes());
            } else {
                channel.basicPublish("", QUUEUE_NAME, null, message.getBytes());
            }
        }
        System.out.println("消息发送完毕");


    }
}
